home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
VISUALBA
/
PROG914.ZIP
/
PROGTEXT.DOC
< prev
next >
Wrap
Text File
|
1994-01-08
|
40KB
|
948 lines
PROGTEXT.DOC - by: Ira F. Kavaler - March and April, 1987
Beginner's BASIC - Ira F. Kavaler - 3/14/85 - 1/8/94
The BASIC Language.
-------------------
BASIC is the name of a high-level computer language that is
furnished with the vast majority of personal computers. BASIC stands
for Beginners All-Purpose Symbolic Instruction Code. BASIC is not a
new language; it has been in use for 25 years. It is not an original
language; it was derived from the most popular language of all time,
FORTRAN (FOrmula TRANslator). Both of these languages were created for
scientists and engineers; however, since both have become very easy to
use in the past decade, almost every field where computers can be
beneficial, BASIC (and FORTRAN) can be used as a general purpose
programming language.
BASIC consists of a set of "commands". A command is a word or an
abbreviation that tells the computer to perform a task. Commands
usually require some additional information called "arguments" which
specify the object of the task. An instruction or "statement" contains
the total information, command and argument(s). The statements are
arranged in a logical sequence to produce a "program".
Line Numbers.
-------------
If you have ever followed a set of instructions you have noticed
that each instruction is given a number. This number serves two
purposes:
1. To determine the proper order (sequence) of the instructions, and
2. To provide a reference to any specific instruction should that
become necessary.
The computer program also uses such a numbering system for the
same reasons; each statement number is called a "line number" since
each statement in the program is usually written one to a line. "Line
numbers" must be positive integers; that is, zero, negative numbers,
and non-whole numbers areNot allowed.
You might want to number your lines starting with "1" and
continuing, incrementing the number by one, until all lines have been
numbered. Although there is no reason why this method would not work,
a much better practice is to start with line number "10" and continue
incrementing each subsequent line number by ten. The advantage is that
if you have forgotten a statement in theMiddle of the program, you will
have unused numbers in-between the existing line numbers.
Nearly 90% of all computer programs can be written using only six
easily understood elementary commands: LET, PRINT, INPUT, GOTO,
IF...THEN, and END. There are dozens of other commands that make
writing a program a very simple and concise task; however, you will
discover that they areSubstitutes for commonly encountered sequences of
the six elementary commands.Numeric constants.
For many years the art of computer programming was kept a deep,
dark secret by the mathematicians of the world. By the way, computer
programmers were called mathematicians in the "olden days" (1930's
through 1960's). In order to retain the secret, many mysterious terms
were either adopted or coined for the computer and programming
vocabulary; "constant" is such a term. A "constant" is a number which
represents a quantity or an amount. In general, a "constant" is
anything that is fixed in value. To be more precise, this type of
constant is called a "numeric constant", as it only pertains to
quantities or amounts. Constants are like the numbers you would enter
into a calculator:
the digits zero "0" through nine "9",
the decimal point ".",
the plus "+" and minus "-" signs
(which denote positive and negative Numbers), and
the letter "E" (exponent) is also used as a symbol to indicate
scientific notation (10 to a power).
On a scientific calculator the key is labelled either "EE" (enter
exponent) or "EXP".
1234567890 = 1.23456789 X 10 (to the 9th power)
= 1.23456789E+9
0.0002468 = 2.468 X 10 (to the minus 4th power)
= 2.468E-4
There is another category called "string constants" that involves
names, addresses, dates, etc. "Strings" will be covered at a later
time.
Flow Charting.
--------------
The easiest way to start writing a program is to diagram it; that
is, diagram the steps necessary to solve the problem. Over the years
some symbols have been adopted by different disciplines for this
purpose. These symbols are not standardized, and are left to you to
use what you feel confortable using. The following are my set:
BASIC Command Flow chart symbol
------------- -----------------
LET a rectangle
INPUT a rectangle with the upper left corner cut-off
(so it looks like a computer punch card)
PRINT a rectangle with a one cycle sine wave at the
bottom
(so it looks like a sheet of paper torn-off)
STOP or END an octagon
(so it looks like a stop sign)
IF...THEN a diamond
the program first line an upside-down triangle
(so it looks like a yield sign)
GOTO a circle (see text)
The flow chart symbols are interconnected with arrows showing the
direction of progress from one command to the next. Exclding the
IF...THEN diamond, each symbol can only have one aroow leaving it, but
can have one or more arrows poinmting to it.
The IF...THEN diamond must have only two arrows leaving it, one if
the logical expression is evaluated "true" and the other if the logical
expression is evaluated "false". It can have one or more arrows
poinmting to it.
The STOP or END octagon cannot have any leaving arrows. (There is
one very advacned condition, where a CONTINUE command is executed, that
allows for a leaving arrow, but it is seldom used.)
The GOTO is normally not symbolized, the arrows are just drawn to
indicate the path of the GOTO; however, if the destination of the GOTO
is far away from the source of the GOTO, or it is on another sheet of
paper, etc., the source GOTO is terminated in a circle which has a
specific label; the destination of the GOTO originates at a circle
having the same label, with an arrow to the destination command.
The REM command is not indicated on the flow chart.
Numeric Variables.
------------------
As some of the better calculators have memories which can hold
numbers, the computer also has memories. Usually the calculator's
memories will be numbered: M1, M2, M3, etc. One problem is that you
must remember which memory holds what constant.
The computer does not number the memories, but instead allows you
to give them names. If you wanted the computer to hold the balance of
your checking account, you could call it BALANCE. The computer will
automatically assign one of its memories for this purpose and use it
anytime you specify BALANCE. Similarly, you could hold the deposit you
made to your account as DEPOSIT, and there would be no problem. In
fact, the computer has the ability to hold hundreds of memories,
limited only by the "size" of your computer system. These so-called
memories that you can name for your specific purpose are called
"variables", and since they hold "numeric constants", they are called
"numeric variables". But I now must clarify one point; most computers
only use the first two characters of the variable name, although your
name may be upto 16 characters long. The IBM and compatibles use all
16 characters. Consider a program where you are a farmer and have to
keep track of how many apples and apricots you have harvested. If you
use the variable names APPLES and APRICOTS, most computers will not
keep the two constants in separate variables; both "APPLES and
APRICOTS start with the same two letters "AP", and if the computer only
uses the first two characters when it assigns memory to the variable
names. You will have to choose a different name for one of the two
names, such as "ap" for apples and "ar" f